<template>
  <div class="loginOut-container">
    <div class="page-title1">{{ pageName }}</div>
    <div class="loginOut">
      <div class="loginOut-name">登陆人:{{ userInfo.nickname }}</div>
      <div class="loginOut-btn" @click="loginOut"
        ><el-icon style="margin-right: 3px"><UserFilled /></el-icon>退出</div
      >
    </div>
  </div>
</template>

<script setup>
import { useUserStore } from '@/store/modules/user'
import { useTagsViewStore } from '@/store/modules/tagsView'
import { useRouter } from 'vue-router'
import { UserFilled } from '@element-plus/icons-vue'

const props = defineProps({
  pageName: {
    type: String,
    default: ''
  }
})

const userInfo = JSON.parse(localStorage.getItem('userInfo'))

const router = useRouter()
const userStore = useUserStore()
const tagsViewStore = useTagsViewStore()
const { t } = useI18n()
const loginOut = async () => {
  try {
    await ElMessageBox.confirm(t('common.loginOutMessage'), t('common.reminder'), {
      confirmButtonText: t('common.ok'),
      cancelButtonText: t('common.cancel'),
      type: 'warning'
    })
    await userStore.loginOut()
    tagsViewStore.delAllViews()
    router.push('/login?redirect=/index')
  } catch {}
}
</script>
<style lang="less" scoped>
.loginOut-container {
  position: fixed;
  top: 0px;
  left: 0px;
  height: 60px;
  display: flex;
  justify-content: space-between !important;
  align-items: center;
  width: 100%;

  .page-title1 {
    font-size: 16px;
    font-weight: 500;
    margin-left: 30px;
  }
  .loginOut {
    display: flex;
    align-items: center;
    justify-content: space-between;
    width: 160px;
    position: fixed;
    top: 20px;
    right: 20px;

    .loginOut-name {
      font-size: 14px;
      font-weight: 500;
    }
    .loginOut-btn {
      display: flex;
      align-items: center;
      font-size: 14px;
      font-weight: 500;
      cursor: pointer;
    }
  }
}
</style>
